package com.neu.controller;
/**
 * 
 * @author neustu
 * 根据控制台输入的信息，完成对应功能方法的调用
 */
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

import com.neu.dao.StudentDao;
import com.neu.daoimpl.StudentDaoImpl;
import com.neu.entity.Student;

public class StudentManager {
 private static Scanner sc=new Scanner(System.in);
 public static void main(String[] args)throws SQLException, ClassNotFoundException {
	System.out.println("************欢迎使用学生管理系统*************");
	while(true) {
//		selectOperation();
		selectOperation1();
	}
}
 /**
  * 定义封装逻辑业务的方法调用
  * @throws SQLException 
  * @throws ClassNotFoundException 
  */
 public static void selectOperation1() throws ClassNotFoundException, SQLException {
	 StudentDao sd=new StudentDaoImpl();
	 Student stu=null;
	 System.out.println("请输入操作的信息:");
	 System.out.println("1.修改个人的信息:");
	 System.out.println("2.查看个人的信息:");
	 System.out.println("3.退出系统;");
	 int op = sc.nextInt();
	 switch(op) {
	 case 1:
		 System.out.println("请输入您要学生本人对应的编号:");
		 int e = sc.nextInt();
		 System.out.println("请输入您要修改学生信息对应的姓名:");
		 String f = sc.next();
		 System.out.println("请输入您要修改学生信息对应的地址:");
		 String g = sc.next();
		 System.out.println("请输入您要修改学生信息对应的年龄:");
		 int h = sc.nextInt();
		 System.out.println(sd.updateStudent(new Student(e, f, g, h)));
		 break;
	 case 2:
		 System.out.println("请输入您要查询学生对应的编号:");
		 int i = sc.nextInt();
		System.out.println(sd.findOneStudent(i));
		 break;
	 case 3:
		 System.out.println("***********谢谢使用学生管理系统************");
		 System.exit(0);
		 break;
		 default:
			 System.out.println("无操作项");
	 }
 }
 public static void selectOperation() throws SQLException, ClassNotFoundException{
	 StudentDao sd=new StudentDaoImpl();
	 Student stu=null;
	 //StudentDaoImpl sdi=new StudentDaoImpl();
	 System.out.println("请输入操作信息：  ");
	 System.out.println("1.添加学生");
	 System.out.println("2.删除学生");
	 System.out.println("3.修改学生");
	 System.out.println("4.查询单个学生信息");
	 System.out.println("5.查询所有学生信息");
	 System.out.println("6.退出系统");
	 //获取操作符号
	 int op=sc.nextInt();
	 //通过判断用户所选择的具体数值完成对应功能的调用
	 switch(op) {
	 case 1:
		 //  增加
		 System.out.println("请输入你要添加学生的名字:");
		 String a = sc.next();
		 System.out.println("请输入你要添加的学生地址:");
		 String b = sc.next();
		 System.out.println("请输入你要添加的学生姓名:");
		 int c = sc.nextInt();
		 System.out.println(sd.addStudent(new Student(0, a, b, c)));
		 break;
	 case 2:
		 //  删除
		 System.out.println("请输入你要删除学生的编号:");
		 int d = sc.nextInt();
		System.out.println(sd.deleteStudentById(d));
		 break;
	 case 3:
		 //  修改
		 System.out.println("请输入您要本人对应的编号:");
		 int e = sc.nextInt();
		 System.out.println("请输入您要修改学生信息对应的姓名:");
		 String f = sc.next();
		 System.out.println("请输入您要修改学生信息对应的地址:");
		 String g = sc.next();
		 System.out.println("请输入您要修改学生信息对应的年龄:");
		 int h = sc.nextInt();
		 System.out.println(sd.updateStudent(new Student(1, f, g, h)));
		 break;
	 case 4:
		 //   查询单一的   
		 System.out.println("请输入您要查询学生对应的编号:");
		 int i = sc.nextInt();
		System.out.println(sd.findOneStudent(i));
		 break;
	 case 5:
		 //  查询全部
		 List<Student> list=sd.findAll();
		 //遍历集合，显示信息
		 Iterator<Student> ite=list.iterator();
		 while(ite.hasNext()) {
			 stu=ite.next();
			 System.out.println(stu);
		 }
		 break;
	 case 6:
		 System.out.println("***********谢谢使用学生管理系统************");
		 System.exit(0);
		 break;
		 default:
			 System.out.println("无操作项");
	 }
 }
}
